package com.cssw.fyzb.busi.api.video;

import com.cssw.fyzb.core.model.vo.video.VideoVo;
import com.cssw.fyzb.busi.service.video.VideoService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.*;
import com.ydn.dbframe.plugin.activerecord.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 添加视频
 *
 * @author Feng Chen
 */
@Function(description = "查询视频", parameters = {
        @Parameter(name = "userId", type = Type.Integer, description = "用户标识", required = true),
        @Parameter(name = "audit", type = Type.String, description = "审核状态(1-审核中 2-审核成功 3-审核失败)", required = false),
        @Parameter(name = "pageNumber", type = Type.Integer, description = "当前页，从1开始", required = true),
        @Parameter(name = "pageSize", type = Type.Integer, description = "页大小", required = true),
}, result = @Result(
        properties = {
                @Property(name = "total", type = Type.Integer, description = "总页数"),
                @Property(name = "count", type = Type.Integer, description = "总行数"),

        },
        listProperties = {
                @ListProperty(name = "list", properties = {
                        @Property(name = "id", type = Type.Integer, description = "视频编号"),
                        @Property(name = "title", type = Type.Integer, description = "视频主题"),
                        @Property(name = "href", type = Type.Integer, description = "视频地址"),
                        @Property(name = "thumb", type = Type.Integer, description = "视频封面"),
                        @Property(name = "likes", type = Type.Integer, description = "点赞数"),
                        @Property(name = "views", type = Type.Integer, description = "浏览数"),
                        @Property(name = "comments", type = Type.Integer, description = "评论数"),
                        @Property(name = "shares", type = Type.Integer, description = "分享数"),
                        @Property(name = "audit", type = Type.Integer, description = "审核状态(1-审核中 2-审核成功 3-审核失败)"),
                })
        }
))

@Component
public class ListVideo implements Action {

    @Autowired
    private VideoService videoService;

    private static final Logger logger = LoggerFactory.getLogger(ListVideo.class);

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");
        String audit = request.getString("audit");
        Integer pageNumber = request.getInteger("pageNumber");
        Integer pageSize = request.getInteger("pageSize");
        try {
            Page<VideoVo> page = videoService.pageByUserId(userId, audit, pageNumber, pageSize);

            return Response.success().put("list", page.getList()).put("total", page.getTotalPage()).put("count", page.getTotalRow());
        } catch (Exception e) {
            logger.info("", e);
            return Response.fail("操作异常");
        }
    }

}
